package com.guyj.common.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.guyj.baseapp.R;

/**
 * Created by Bada on 2016/10/12.
 */
public class EasySettingItem extends RelativeLayout {
    private ImageView icon;
    private TextView text;
    private ImageView arrow;
    private LayoutParams iconParams;
    private LayoutParams textParams;
    private LayoutParams arrowParams;
    private int isIconVisibility;
    private int isArrowVisibility;
    private int iconResID;
    private int arrowResID;
    private String textContent;
    private int textColor;
    private int textSize;


    public EasySettingItem(Context context) {
        super(context);
    }

    public EasySettingItem(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public EasySettingItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    private void initAttrs(AttributeSet attrs) {
        TypedArray typedArray = this.getContext().obtainStyledAttributes(attrs,
                R.styleable.EasySettingItem);
        if (typedArray != null) {
            iconResID = typedArray.getResourceId(R.styleable.EasySettingItem_iconResID,0);
            arrowResID = typedArray.getResourceId(R.styleable.EasySettingItem_arrowResID,0);

            typedArray.recycle();
        }
    }

    private void initView(Context context){
        icon=new ImageView(context);
        text=new TextView(context);
        arrow=new ImageView(context);
        icon.setVisibility(isIconVisibility);
        icon.setImageResource(iconResID);
        arrow.setVisibility(isArrowVisibility);
        arrow.setImageResource(arrowResID);
        text.setText(textContent);
        text.setTextColor(textColor);
        text.setTextSize(textSize);
        iconParams=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        iconParams.addRule(ALIGN_PARENT_LEFT);
        iconParams.addRule(CENTER_VERTICAL);
        arrowParams=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        arrowParams.addRule(ALIGN_PARENT_RIGHT);
        arrowParams.addRule(CENTER_VERTICAL);
        textParams=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        textParams.addRule(RelativeLayout.RIGHT_OF,iconResID);
        textParams.addRule(RelativeLayout.LEFT_OF,arrowResID);
        textParams.addRule(CENTER_VERTICAL);
        addView(icon,iconParams);
        addView(arrow,arrowParams);
        addView(text,textParams);
    }
}
